package ace.cmp.sdk.feign.api;

import ace.cmp.core.model.R;
import ace.cmp.sdk.api.SdkApi;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author caspar
 * @date 2023/9/14 19:08
 */
public interface SdkFeignApi<EntityDtoT, IdT> extends SdkApi<EntityDtoT, IdT> {

  String SAVE_URI = "/save";
  String SAVE_NOT_NULL_FIELD_URI = "/saveNotNullField";
  String ADD_URI = "/add";
  String ADD_NOT_NULL_FIELD_URI = "/addNotNullField";
  String MODIFY_URI = "/modify";
  String MODIFY_NOT_NULL_FIELD_URI = "/modifyNotNullField";
  String REMOVE_BY_ID_URI = "/remove";
  String REMOVE_LOGIC_BY_ID_URI = "/removeLogic";
  String GET_BY_ID_URI = "/get";
  String GET_LIST_BY_ID_IN_URI = "/list";
  String GET_MAP_BY_ID_IN_URI = "/map";
  String SEARCH_URI = "/search";

  /**
   * 保存，新增或者修改,处理所有字段
   */
  @PostMapping(SAVE_URI)
  R<IdT> save(@Valid @NotNull @RequestBody EntityDtoT input);

  /**
   * 保存，新增或者修改,只处理不为null的字段
   */
  @PostMapping(SAVE_NOT_NULL_FIELD_URI)
  R<IdT> saveNotNullField(@Valid @NotNull @RequestBody EntityDtoT input);

  /**
   * 新增,处理所有字段
   *
   * @param input
   * @return
   */
  @PostMapping(ADD_URI)
  R<IdT> add(@Valid @NotNull @RequestBody EntityDtoT input);

  /**
   * 新增,只处理不为null的字段
   *
   * @param input
   * @return
   */
  @PostMapping(ADD_NOT_NULL_FIELD_URI)
  R<IdT> addNotNullField(@Valid @NotNull @RequestBody EntityDtoT input);

  /**
   * 修改,处理所有字段
   *
   * @param input
   * @return
   */
  @PostMapping(MODIFY_URI)
  R<IdT> modify(@Valid @NotNull @RequestBody EntityDtoT input);

  /**
   * 修改,只处理不为null的字段
   *
   * @param input
   * @return
   */
  @PostMapping(MODIFY_NOT_NULL_FIELD_URI)
  R<IdT> modifyNotNullField(@Valid @NotNull @RequestBody EntityDtoT input);

  /**
   * 删除
   *
   * @param ids
   * @return
   */
  @PostMapping(REMOVE_BY_ID_URI)
  R<Boolean> remove(@Valid @NotEmpty @RequestBody List<IdT> ids);

  /**
   * 逻辑删除
   *
   * @param ids
   * @return
   */
  @PostMapping(REMOVE_LOGIC_BY_ID_URI)
  R<Boolean> removeLogic(@Valid @NotEmpty @RequestBody List<IdT> ids);

  /**
   * 获取明细
   *
   * @param id
   * @return
   */
  @GetMapping(GET_BY_ID_URI)
  R<EntityDtoT> getById(@Valid @NotNull @RequestParam("id") IdT id);

  /**
   * 根据id批量获取
   *
   * @param ids
   * @return
   */
  @GetMapping(GET_LIST_BY_ID_IN_URI)
  R<List<EntityDtoT>> getListByIdIn(@Valid @NotEmpty @RequestParam("ids") IdT... ids);

  /**
   * 根据id批量获取,返回Map数据结构，key:实体id,value:实体
   *
   * @param ids
   * @return
   */
  @GetMapping(GET_MAP_BY_ID_IN_URI)
  R<Map<IdT, EntityDtoT>> getMapByIdIn(@Valid @NotEmpty @RequestParam("ids") IdT... ids);
}
